
#include "nh_base_alg.h"


/**
 * @brief line trend
 */
 typedef enum{
    SIGNAL_RISE=0, 
    SIGNAL_FALL 
}signal_rise_fall_t;

#define SMOOTH_NUMBER 4
// static const float smooth[SMOOTH_NUMBER] = { 0.134f, 0.366f, 0.5f };


static const float smooth2[SMOOTH_NUMBER] = { 0.18f,0.24f,0.35f,0.23f };

int smooth_data2(int diff, int interval, int max_diff, int *record)
{
    uint8_t i;
    float diff_f;
    if ( (abs(diff) / interval) < max_diff)
    {
        for (i = 0; i < (SMOOTH_NUMBER - 1); i++) 
        {
            record[i] = record[i + 1];
        }
            record[SMOOTH_NUMBER - 1] = diff;
        return diff;
    }

    diff_f = 0.0;
    for (i = 0; i < SMOOTH_NUMBER; i++) 
    {
        diff_f += (double)(record[i]) * smooth2[i];
    }
    diff = (int)diff_f;
    record[SMOOTH_NUMBER - 1] = diff;
    return diff;
}

void InsertionSort(float *data, int size)
{
    uint8_t i = 1;
    int16_t j;
    float  v;
    while (i < size) 
    {
        v = data[i];
        j = i - 1;

        while (j >= 0 && v < data[j]) {
        data[j + 1] = data[j];
        j--;
        }

        data[j + 1] = v;
        i++;
    }
}



















